#include "laser.h"

extern int G_W,G_H;

LASER::LASER(SCENE *scene, QTimeLine *global_tl, CASH *cash):QGraphicsObject()
{

    shot = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_3/shot.ogg",this);

    border = cash->cash_poly->value("Res/weapons/Laser_1/Laser.poly");

    shot_music_run=false;

    point=10;

    im = cash->cash_pixmap->value("Res/weapons/Laser_1/Laser.png");

    this->setZValue(0.5);

    timer_id=startTimer(100);

    fire_now=false;

    this->hide();

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,10);

    this->setPos(- G_W, - G_H);

}

QRectF LASER::boundingRect() const
{

    return QRectF( QPointF(0,0),im->size() );

}

QPainterPath LASER::shape() const
{
    return *border;
}

void LASER::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*im );
    painter->restore();

}

void LASER::timerEvent(QTimerEvent *)
{

    if(!fire_now) return;

    if(!shot_music_run){
        shot->Play_Now();
        shot_music_run=true;
    }

    if(this->isVisible())
        this->hide();
    else
        this->show();

}

LASER::~LASER()
{
    shot->Stop();
    killTimer(timer_id);
}

int LASER::type() const
{

    return point;

}

void LASER::I_Am_Move(QPoint oba)
{

    fire_now=true;
    this->setPos(QPoint(oba.x()+8,oba.y()));

}
